package com.xuan.config;

import com.xuan.base.constant.MQConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Lenovo
 * @description: TODO RabbitMQ配置队列交换机绑定URL
 * @date 2021/7/26 10:42
 */
@Configuration
public class MQConfig {


    /**
     * @description: 向资源服务缓存redis消息
     * @param
     * @return: org.springframework.amqp.core.Queue
     * @author Lenovo
     * @date: 2021/7/26 11:01
     */
    @Bean
    public Queue getResourceQueue(){
        //是否持久化
        //是否排外
        //是否自动删除
        return new Queue(MQConstant.ADD_REDIS_RESOURCE_QUEUE,true,false,false);
    }

    /**
     * @description:  向资源服务缓存redis消息
     * @param
     * @return: org.springframework.amqp.core.DirectExchange
     * @author Lenovo
     * @date: 2021/7/26 11:07
     */
    @Bean
    public DirectExchange getResourceExchange(){
        return new DirectExchange(MQConstant.ADD_REDIS_EXCHANGE,true,false);
    }

    /**
     * @description: 向资源服务缓存redis消息
     * @param
     * @return: org.springframework.amqp.core.Binding
     * @author Lenovo
     * @date: 2021/7/26 11:07
     */
    @Bean
    public Binding bindingAddResource(){
        return BindingBuilder.bind(getResourceQueue()).to(getResourceExchange()).with(MQConstant.ADD_REDIS_BINDING_URL);
    }

}
